<?php
namespace Common\Wechat;
use Exception;
class Curl{
   public function http_curl($url,$type='get',$res='json',$arr=''){
        $ch  =curl_init();
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch,CURLOPT_SSLVERSION, 1);
            curl_setopt($ch,CURLOPT_HEADER, 0); // 过滤HTTP头
            curl_setopt($ch,CURLOPT_URL,$url);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
            if($type == 'post'){
	 curl_setopt($ch,CURLOPT_HEADER, 0); // 过滤HTTP头
	 curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
            curl_setopt($ch,CURLOPT_POST,1);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$arr);
            curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        }
        $output =curl_exec($ch);
        curl_close($ch);
        if($res=='json'){
            if(curl_error($ch)){
                return curl_error($ch);
            }else{
                return json_decode($output,true);
            }
        }
    }
}